Unbreak with Ruby <2.0 not having File::FNM_EXTGLOB.

Akinori MUSHA 10 years ago
parent
commit
bf3fe8f1b5
1 changed files with 9 additions and 1 deletions
  1. 9 1
      app/models/agents/imap_folder_agent.rb

+ 9 - 1
app/models/agents/imap_folder_agent.rb

@@ -90,6 +90,14 @@ module Agents
90 90
 
91 91
     IDCACHE_SIZE = 100
92 92
 
93
+    FNM_FLAGS = [:FNM_CASEFOLD, :FNM_EXTGLOB].inject(0) { |flags, sym|
94
+      if File.const_defined?(sym)
95
+        flags | File.const_get(sym)
96
+      else
97
+        flags
98
+      end
99
+    }
100
+
93 101
     def working?
94 102
       event_created_within?(options['expected_update_period_in_days']) && !recent_error_logs?
95 103
     end
@@ -343,7 +351,7 @@ module Agents
343 351
     end
344 352
 
345 353
     def glob_match?(pattern, value)
346
-      File.fnmatch?(pattern, value, File::FNM_CASEFOLD | File::FNM_EXTGLOB)
354
+      File.fnmatch?(pattern, value, FNM_FLAGS)
347 355
     end
348 356
 
349 357
     class Client < ::Net::IMAP